//
//  AppDelegate.m
//  Le way walkers
//
//  Created by POP-mac on 15/5/13.
//  Copyright (c) 2015年 LTXZ. All rights reserved.
//

#import "AppDelegate.h"
#import "XDRecommendViewController.h"
#import "XDPersonViewController.h"
#import "XDPlaceViewController.h"
#import "XDShakeViewController.h"
#import "UMSocial.h"
#import "AFNetworkReachabilityManager.h"
#import "MBProgressHUD.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"viewBack"]];
    [self.window makeKeyAndVisible];

    XDRecommendViewController *oneVC = [[[XDRecommendViewController alloc] init] autorelease];
    UINavigationController *navi_1 = [[[UINavigationController alloc] initWithRootViewController:oneVC] autorelease];
    UIImage *image_1 = [[UIImage imageNamed:@"Image"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    oneVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"推荐" image:image_1 tag:1001] autorelease];
    
    XDPlaceViewController *twoVC = [[[XDPlaceViewController alloc] init] autorelease];
    UINavigationController *navi_2 = [[[UINavigationController alloc] initWithRootViewController:twoVC] autorelease];
    UIImage *image_2 = [[UIImage imageNamed:@"Image-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    twoVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"目的地" image:image_2 tag:1002] autorelease];
    
    XDShakeViewController *threeVC = [[[XDShakeViewController alloc] init] autorelease];
    UINavigationController *navi_3 = [[[UINavigationController alloc] initWithRootViewController:threeVC] autorelease];
    UIImage *image_3 = [[UIImage imageNamed:@"Image-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    threeVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"摇一摇" image:image_3 tag:1003] autorelease];
    
    XDPersonViewController *fourVC = [[[XDPersonViewController alloc] init] autorelease];
    UINavigationController *navi_4 = [[[UINavigationController alloc] initWithRootViewController:fourVC] autorelease];
    UIImage *image_4 = [[UIImage imageNamed:@"Image-3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    fourVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我的" image:image_4 tag:1004] autorelease];
    
    UITabBarController *tabBar = [[[UITabBarController alloc] init] autorelease];
    tabBar.viewControllers = @[navi_1, navi_2, navi_3, navi_4];
//    NSDictionary * dict = @{NSFontAttributeName:[UIFont systemFontOfSize:11],NSForegroundColorAttributeName:[UIColor whiteColor]};
//    [navi_1.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    tabBar.delegate = self;
    [tabBar.tabBar setBarTintColor:[UIColor colorWithRed:240 / 255.0 green:110 / 255.0 blue:114 / 255.0 alpha:1]];
    [tabBar.tabBar setTintColor:[UIColor whiteColor]];
    tabBar.tabBar.translucent = NO;
    self.window.rootViewController = tabBar;
    
    [_window release];
    
    //友盟登录
    [UMSocialData setAppKey:@"5555c0b367e58e658e0005e2"];
    
    //判断网络
    AFNetworkReachabilityManager *mpg = [AFNetworkReachabilityManager sharedManager];
    [mpg setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        MBProgressHUD *mb = [[MBProgressHUD alloc] initWithView:self.window];
        [self.window addSubview:mb];
        [mb release];
        mb.mode = MBProgressHUDModeCustomView;
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"当前是WIFI环境");
                mb.labelText = @"当前是WIFI环境";
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"当前是手机网络");
                mb.labelText = @"当前是手机网络";
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"当前没有网络");
                mb.labelText = @"当前没有网络";
                break;
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                mb.labelText = @"未知网络";
                break;
            default:
                break;
        }
        [mb showAnimated:YES whileExecutingBlock:^{
            sleep(1);
        } completionBlock:^{
            [mb removeFromSuperview];
        }];
    }];
    [mpg startMonitoring];
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
